/**
 * Created by yangqy on 4/29/16.
 */
Ext.define('JYnovel.view.system.UserInfoForm', {
    extend: 'Ext.form.Panel',
    alias:'widget.system_UserInfoForm',
    requires: [
        'Ext.form.field.ComboBox'
    ],

    border:false,
    bodyPadding: 10,
    buttons:[
        {
            xtype: 'button',
            name:'formSaveBtn',
            text: '保存'
        }
    ],

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    margin: '10 0 10 0',
                    fieldLabel: '账号',
                    labelAlign: 'right',
                    labelWidth: 70,
                    name: 'loginName',
                    allowBlank: false,
                    enforceMaxLength: true,
                    maxLength: 50
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    margin: '10 0 10 0',
                    fieldLabel: '用户名',
                    labelAlign: 'right',
                    labelWidth: 70,
                    name: 'nickName',
                    allowBlank: false,
                    enforceMaxLength: true,
                    maxLength: 10
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    margin: '10 0 10 0',
                    fieldLabel: '密码',
                    labelAlign: 'right',
                    labelWidth: 70,
                    name: 'pwd1',
                    inputType: 'password',
                    allowBlank: false,
                    enforceMaxLength: true,
                    maxLength: 20
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    margin: '10 0 10 0',
                    fieldLabel: '确认密码',
                    labelAlign: 'right',
                    labelWidth: 70,
                    name: 'pwd2',
                    inputType: 'password',
                    allowBlank: false,
                    enforceMaxLength: true,
                    maxLength: 20
                },
                {
                    xtype: 'combobox',
                    anchor: '100%',
                    margin: '10 0 10 0',
                    fieldLabel: '角色',
                    labelAlign: 'right',
                    labelWidth: 70,
                    store:'system.RoleStore',
                    displayField: 'name',
                    valueField: 'id',
                    name: 'roleId',
                    allowBlank: true,
                    editable: false,
                    listConfig: {
                        getInnerTpl: function() {
                            return '<b>{name}</b><div style="color:#AAA;">{des}</div>';
                        }
                    }
                }
            ]
        });

        me.callParent(arguments);
    }

});

Ext.define('JYnovel.view.system.UserGridViewRightMenu', {
    extend: 'JYnovel.view.widget.AuthMenu',
    id:'userGridViewRightMenu',
    requires: [
        'Ext.menu.Item'
    ],
    width: 120,
    border:false,
    beforeShow:function(){
        var userView=Ext.getCmp('userGridPanel');
        var row=userView.getSelectionModel().getSelection()[0];
        var userLockMenu=this.queryById('userLockMenu');
        var userUnLockMenu=this.queryById('userUnLockMenu');
        switch (row.raw.isLock){
            case 0://正常
                userLockMenu.setVisible(true);
                userUnLockMenu.setVisible(false);
                break;
            case 1://锁定
                userLockMenu.setVisible(false);
                userUnLockMenu.setVisible(true);
                break;
        }
    },
    initComponent: function() {
        var me = this;
        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'menuitem',
                    id: 'userEditMenu',
                    text: '编辑',
                    authId:'55da8af994b27456f811f114'
                },
                {
                    xtype: 'menuitem',
                    id: 'userRestPwdMenu',
                    text: '密码重置',
                    authId:'55da8af994b27456f811f115'

                },
                '-'
                ,
                {
                    xtype: 'menuitem',
                    id: 'userLockMenu',
                    text: '锁定',
                    authId:'55da8af994b27456f811f112'
                },
                {
                    xtype: 'menuitem',
                    id: 'userUnLockMenu',
                    text: '解锁',
                    authId:'55da8af994b27456f811f112'
                }
            ]
        });

        me.callParent(arguments);
    }

});

Ext.define('JYnovel.view.system.UserManagerView', {
    extend: 'Ext.container.Container',
    alias:'widget.system_UserManagerView',
    region:'center',
    requires: [
        'Ext.grid.Panel',
        'Ext.grid.View',
        'Ext.grid.column.Date',
        'Ext.toolbar.Paging'
    ],
    layout: 'fit',
    initComponent: function() {
        var me = this;
        var userStore=Ext.create('JYnovel.store.system.UserStore',{autoLoad:true});
        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'gridpanel',
                    id:'userGridPanel',
                    title: '',
                    store:userStore,
                    forceFit: true,
                    sortableColumns: false,
                    emptyText:'无数据',
                    columns: [
                        {
                            xtype: 'gridcolumn',
                            dataIndex: 'id',
                            width:40,
                            text: '用户ID'
                        },
                        {
                            xtype: 'gridcolumn',
                            dataIndex: 'loginName',
                            text: '账号'
                        },
                        {
                            xtype: 'gridcolumn',
                            dataIndex: 'nickName',
                            text: '用户'
                        },
                        {
                            xtype: 'gridcolumn',
                            dataIndex: 'roleName',
                            text: '角色'
                        },
                        {
                            xtype: 'gridcolumn',
                            dataIndex: 'isLock',
                            text: '状态',
                            renderer:function (value) {
                                if (value == '0') {
                                    return '正常';
                                }else if (value=='1'){
                                    return '锁定'
                                }
                            }
                        },
                        {
                            xtype: 'gridcolumn',
                            dataIndex: 'loginTime',
                            text: '上次登录时间'
                            // renderer:AppDateRenderer1
                        }
                    ],
                    dockedItems: [
                        {
                            xtype: 'pagingtoolbar',
                             store:userStore,
                            dock: 'bottom',
                            width: 360,
                            displayInfo: true
                        },
                        {
                            xtype: 'toolbar',
                            dock: 'top',
                            items: [
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '用户名',
                                    emptyText: '账号、用户',
                                    labelWidth: 50,
                                    id:'userName',
                                    name: 'userName'
                                },
                                {
                                    xtype: 'combobox',
                                    width: 200,
                                    fieldLabel: '角色',
                                    // store:'system.RoleStore',
                                    displayField: 'name',
                                    valueField: 'id',
                                    labelAlign: 'right',
                                    labelWidth: 50,
                                    name: 'roleId',
                                    id: 'userRole'
                                },
                                {
                                    xtype: 'combobox',
                                    width: 130,
                                    fieldLabel: '状态',
                                    // store:'system.UserStatusStore',
                                    displayField: 'name',
                                    valueField: 'value',
                                    labelWidth: 40,
                                    id:'status',
                                    name: 'status'
                                },
                                {
                                    xtype: 'button',
                                    text: '查询',
                                    name: 'searchBtn'
                                },
                                {
                                    xtype: 'button',
                                    text: '添加',
                                    // authId:'55da8af994b27456f811f113',
                                    name:'userAddBtn'
                                }
                            ]
                        }
                    ]
                }
            ]
        });
        me.callParent(arguments);
    }
});

